home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
MWCC03.ZIP
/
WINMENU.ZIP
/
WINMENU.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-08-18
|
36KB
|
1,089 lines
{**********************************************************************}
{* *}
{* Microworks Sample Application *}
{* *}
{* for Borland Pascal v7.0 and Turbo Pascal for Windows v1.5 *}
{* *}
{* Copyright 1992-93 Jeff Franks (Microworks) Sydney, Australia. *}
{* *}
{* You are free to use, modify, reproduce and distribute the *}
{* Sample Files (and/or any modified version) in any way you *}
{* find useful. *}
{* *}
{**********************************************************************}
{*** Introduction
Application := Winmenu 3D Ownerdraw Menu Demonstration
Files := Winmenu.exe, Winmenu.pas, Winmenu.res
Requires := MObjects, MMsgBox and MWCC.dll
Purpose := Winmenu shows you how to,
1. Set up a 3D Menu bar using TMWCCButtons and popup menus.
2. Use CreatePopupMenu and TrackPopupMenu.
3. Create ownerdraw popup menus using wm_DrawItem and wm_MenuChar.
4. Use the wh_Keyboard Hook from HotKey1 example.
4. Use some of the objects and custom controls
in the MWCC unit and library.
5. Use the SFXMsgBox and MWCCMsgBox functions instead of
the Windows API MessageBox function.
Tabs := 2
Screen := 800 * 600
Date := August 1993.
{*** About TMWCCWindow
The TMWCCWindow object works differently depending on how you set it up. One of the main
things you should be aware of is the way it uses normal menus and ws_VScroll and ws_HScroll
scroll bars. This is only of concern if you give your window an SFX style frame by setting
SFXFrame := True in the constructor.
The TMWCCWindow and TMWCCDlgWindow objects intercept the wm_NCPaint message to paint their
frame and title bar. After painting, if you pass the message along to DefWndProc it then
draws the normal frame as well. What you would see when you ran the program would be a
quick flash of normal frame colour before my NCPaint routine paints the SFX style frame.
It is reasonably fast and most noticeable when you resize the window. This is how the
Microsoft Ctl3d.dll paints its frames. It just paints over the existing colours.
Well, I wasn't satisfied with that. I don't like seeing flashing colours. The
only alternative was to draw the non-client area myself(What a pain!!!). It was easy to
draw the frame and the title bar but I couldn't get the menu bar or scroll bars to
display properly. If your window doesn't use menu's or scroll bars then its Ok.
You don't pass the wm_NCPaint message onto DefWndProc, you draw the frame yourself and you
don't see any flashing colours. Unfortunaletly, most windows need atleast a menu and
often a scroll bar.
My solution was to optionally pass wm_NCPaint along to DefWndProc. If the Attr.Style
includes ws_VScroll or ws_HScroll or if your window has a class menu then wm_NCPaint
is passed to DefWndProc and the non-client area is drawn normally. If you use an
SFX style frame it just gets drawn over the top. When your window doesn't use a class
menu and/or doesn't have ws_VScroll or ws_HScroll in its Attr.Style field then the wm_NCPaint
message is not get passed along to DefWndProc.
(This is a the way SFX objects work (TSFXWindow etc) except they don't pass wm_NCPaint
on at all. Thats why you can't use menus etc with them. If you add a menu or scroll bar
the object destroys them before displaying the window/dialog.)
I think its important to try and give your program classy interface. Thats where 'Winmenu'
comes in. It shows you an alternative way to institute a (3D) menu bar using buttons and
popup menus. It also shows you whats needed to make the separate buttons and menus function
together as a single unit like a normal menu bar. And there's more! It matches the
design on the window, you don't see any colour flashes around the frame and it looks great!
{*** About Winmenu
Winmenu shows you one way to set up a 3D menu bar with ownerdraw menus. I'm still working on
refining the way the menus work so expect some improvements in future.
Drawing ownerdraw menus is much the same as drawing ownerdraw list boxes. In this example
I didn't worry about adding bitmap glyphs for each menu item but you can easily add them
in same way you would to ownerdraw list box items (see Wintask).
I played around with several ideas for ownerdraw menus until I came up with the menus in
Winmenu. Each menu item is drawn as a separate 3D block and uses its own 'checked' bitmap
when checked (see Object Viewer). I didn't bother about menu separators. If you want
separators you'll have to add them to the wm_DrawItem method yourself. After looking at
the way OS/2 draws its menus (and other programs) I felt it looked better to have the
highlighted menu item a different colour. The default highlight text and background only
look good with a bold font and I didn't want a bold font. If I use these menus as is, I will
let the user select the highlight background and highlight text color as an option.
I tried making the menu items look like buttons but it didn't look right because regular
menus don't operate like buttons.
The wm_MenuChar method method handles the menu item's keyboard mnemonic. This method is very
important when you draw ownerdraw menus.
The other methods like wm_Hotkey, wm_ResetMenus and the TMenuButtons are all designed to
make the 3D menus work more like regular menus.
I hope you find this example useful.
Jeff...
***}
program WinMenu;
{$R WinMenu.res}
uses WinTypes, WinProcs, WinDos, Win31, Strings, MObjects, MMsgBox,
{$IFDEF Ver15}
WObjects;
{$ELSE}
Objects, OWindows, ODialogs;
{$ENDIF}
const
{*** Menu Button ID's ***}
idm_But1 = 201;
idm_But2 = 202;
idm_But3 = 203;
idm_But4 = 204;
idm_But5 = 205;
{*** Window Static ID ***}
idw_Stat1 = 401;
{*** About Dialog ID's ***}
idd_OkBut = 402;
{*** Menu Item ID's ***}
idm_Item1 = 701;
idm_Item2 = 702;
idm_Item3 = 703;
idm_Item4 = 704;
idm_About = 705;
{*** Miscellaneous ID's ***}
pToHotKeyHookProc : TFarProc = nil;
wm_HotKey = wm_User + 76;
wm_ResetMenus = wm_User + 202;
AppName : PChar = 'WinMenu';
type
PAboutDialog = ^TAboutDialog;
TAboutDialog = object(TMWCCDialog)
{***
TMWCCBmpButton is a BWCC style bitmap button object. TMWCCStatic is a static object
that displays either raised, recessed or normal static controls. WMDrawItem is required
to draw the TMWCCBmpButton ownerdraw button object.
***}
OkBut : PMWCCBmpButton;
ST1, ST2 : PMWCCStatic;
constructor Init (AParent: PWindowsObject; AName, ABmp: PChar);
procedure SetUpWindow; virtual;
procedure WMDrawItem (var Msg: TMessage); virtual wm_First + wm_DrawItem;
end;
PMenuButton = ^TMenuButton;
TMenuButton = object(TMWCCButton)
{***
The TMWCCButton object draws a button displaying either Text or a single Bitmap.
MWCCButtons don't support the 'default' field. That's so you can draw recessed (etc)
buttons without thick black borders spoiling the 3D effect.
TMenuButton overrides the default TMWCCButton font and creates a larger font suitable
for menus. It also sets up the wm_MouseMove mehtod to reset all the menus.
***}
MenuFont : HFont;
destructor Done; virtual;
procedure SetupWindow; virtual;
procedure WMMouseMove (var Msg: TMessage); virtual wm_First + wm_MouseM